package org.project.d.network;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
 * @author lin
 * @version V1.0
 * @description
 * @date 2020/9/29 5:31 下午
 */
public class TcpConnectionManager {
//    XXX TcpConnectionManager 可以重构为Connection pool
    private static final Map<String, Connection> tcpConnection = new ConcurrentHashMap<>(8);

    public static Connection putIfAbsent(String key, Connection value){
        return tcpConnection.putIfAbsent(key,value);
    }

    public static Connection computeIfAbsent(String key, Function<String, Connection> mappingFunction){
        return tcpConnection.computeIfAbsent(key,mappingFunction);
    }
    public static Connection put(String key, Connection value){
        return tcpConnection.put(key,value);
    }

    public static Connection get(String key){
        return tcpConnection.get(key);
    }

    public static Connection remove(String key){
        return tcpConnection.remove(key);
    }
}
